import { http } from '../utils/http/index'

// 行业数据接口
export interface IndustryItem {
  id: string
  name: string
  sort: number
  fatherId: string
  isLeaf: boolean
  level: number
}

// 字典数据接口
export interface DictionaryItem {
  id: number
  typeKey: string
  dataKey: string
  parentDataKey: string | null
  value: string
  remark: string
  sort: number
  status: number
  icon: string | null
}

/**
 * 获取一级行业列表
 */
export async function getIndustryTopList(): Promise<IndustryItem[]> {
  const response = await http.get('/portal/recourse/get_industry_top_list')
  return response as IndustryItem[]
}

/**
 * 根据父级ID获取子级行业
 */
export async function getChildrenIndustry(id: string): Promise<IndustryItem[]> {
  const response = await http.get(`/portal/recourse/get_children_industry?id=${id}`)
  return response as IndustryItem[]
}

// 城市信息接口
export interface CityItem {
  id: number
  name: string
  fullName: string
  parentId: number
  pinyin: string
  level: number
  longitude: number
  latitude: number
}

// 城市拼音列表响应（按首字母分组）
export type CityPinyinList = Record<string, CityItem[]>

/**
 * 获取城市拼音列表
 */
export async function getCityPinyinList(): Promise<CityPinyinList> {
  const response = await http.get('/portal/recourse/map/city_pinyin_list')
  return response as CityPinyinList
}

/**
 * 获取热门城市列表
 */
export async function getCityHotList(): Promise<CityItem[]> {
  const response = await http.get('/portal/recourse/map/city_hot_list')
  return response as CityItem[]
}

/**
 * 根据字典类型获取字典数据
 */
export async function getDictionaryDatasByTypeKey(typeKey: string): Promise<DictionaryItem[]> {
  const response = await http.get(`/portal/recourse/get_dictionary_datas_typekey?typeKey=${typeKey}`)
  return response as DictionaryItem[]
}

/**
 * 批量获取字典数据请求体
 */
export interface BatchDictionaryRequest {
  typeKeys: string[]
}

/**
 * 批量获取字典数据响应
 */
export type BatchDictionaryResponse = Record<string, DictionaryItem[]>

/**
 * 批量获取字典数据
 */
export async function getDictionaryDatasByTypeKeys(typeKeys: string[]): Promise<BatchDictionaryResponse> {
  const response = await http.post('/portal/recourse/get_dictionary_datas_typekeys', { typeKeys })
  return response as BatchDictionaryResponse
}

// 职位类型数据接口（复用 IndustryItem 的结构）
export type JobTypeItem = IndustryItem

/**
 * 获取一级职位类型列表
 */
export async function getJobTypeTopList(): Promise<JobTypeItem[]> {
  const response = await http.get('/portal/recourse/job_type/get_top_list')
  return response as JobTypeItem[]
}

/**
 * 根据父级ID获取子级职位类型
 */
export async function getChildrenJobType(fatherId: string): Promise<JobTypeItem[]> {
  const response = await http.get(`/portal/recourse/job_type/get_children_list?fatherId=${fatherId}`)
  return response as JobTypeItem[]
}

// 专业数据接口
export interface MajorItem {
  id: string
  name: string
  code: string
  sort: number
  fatherId: string
  isLeaf: boolean
  level: number
}

/**
 * 获取一级专业列表
 */
export async function getMajorTopList(): Promise<MajorItem[]> {
  const response = await http.get('/portal/recourse/major/get_top_list')
  return response as MajorItem[]
}

/**
 * 根据父级ID获取子级专业
 */
export async function getChildrenMajor(id: string): Promise<MajorItem[]> {
  const response = await http.get(`/portal/recourse/major/get_children_list?id=${id}`)
  return response as MajorItem[]
}

